/*
 * MusicLabs, Copyright (C) 2008-2009 Felippe Ragghianti
 * http://code.google.com/p/musiclabs
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */


package br.com.music.scale;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import br.com.music.Interval;
import br.com.music.Pitch;

// TODO FIXME Fix javadocs bellow (Tetrachords does not exist yet, and links
// are not working properly).

/**
 * Diatonic scale is formed by two {@link Tetrachords} separated by a {@link TONE}.
 * 
 * @version $LastChangedRevision$
 */
public class DiatonicScale extends Scale {

    static {
        /**
         * Diatonic intervals corresponds to two tetrachords separated by
         * a tone.
         */
        //FIXME: these intervals are being loaded incorrectly, probably because this static way of load.
    	// In runtime, the are 12 intervals, where normally would be 7.
    	DiatonicScale.intervals = Arrays.asList(
                new Interval[]{
            Interval.TONE, Interval.TONE, Interval.SEMITONE,
            Interval.TONE,
            Interval.TONE, Interval.TONE, Interval.SEMITONE
        });
    }

    /**
     * Class constructor.
     *
     * @param tonic Diatonic scale tonic.
     */
    public DiatonicScale(Pitch tonic) {
        super(tonic);
    }

    /**
     * Create diatonic scale from a Object's tonic note.
     *
     * @return A list of generic notes.
     */
    @Override
    protected List<Pitch> createScale() {
        List<Pitch> diatonicNotes = new ArrayList<Pitch>(8);
        List<Pitch> cromaticNotes = new CromaticScale(tonic).getNotes();
        int index = 0;
        for (Interval interval : DiatonicScale.intervals) {
            diatonicNotes.add(cromaticNotes.get(index));
            index+=interval.toSemitones();
        }
        diatonicNotes.add(diatonicNotes.get(0));
        return diatonicNotes;
    }

}